package com.y.simple.global;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局捕获异常类，用于全局捕获指定异常并加以处理
 * @author y2014188432
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理 ResultError
     * @param request http请求
     * @param exception 异常
     * @return Result类
     */
    @ExceptionHandler(value = ResultException.class)
    @ResponseBody
    public Result resultExceptionHandler(HttpServletRequest request, ResultException exception){
        return Result.error(exception.getErrorCode(),exception.getErrorMsg());
    }

}
